package woshiheima8;

import java.io.*;

public class CopyAviDemo {
    public static void main(String[] args) throws IOException {
        //记录开始时间
        long startTime = System.currentTimeMillis();

        method2();
        long endTime = System.currentTimeMillis();
        System.out.println("共耗时："+(endTime-startTime)+"毫秒");

    }
     //基本字节流一次读写一个字节
    /*private static void method1() throws IOException {
        //D:\page1开始目录
        FileInputStream fis = new FileInputStream("D:\\page1\\nai1.jpg");
        //目标目录
        FileOutputStream fos = new FileOutputStream("D:\\xuexi\\nai1.jpg");

        int by;
        while ((by = fis.read())!=-1){
            fos.write(by);
        }
        fos.close();
        fis.close();
    }*/
     //基本字节流一次读写一个字节数组
    private static void method1() throws IOException {
        //D:\page1开始目录
        FileInputStream fis = new FileInputStream("D:\\page1\\nai1.jpg");
        //目标目录
        FileOutputStream fos = new FileOutputStream("D:\\xuexi\\nai1.jpg");

        byte[] bys = new byte[1024];
        int len;
        while ((len = fis.read(bys))!=-1){
            fos.write(bys,0,len);
        }
        fos.close();
        fis.close();
    }
    //字节缓冲流一次读写一个字节
    private static void method2() throws IOException {
        //D:\page1开始目录
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\page1\\nai1.jpg"));

        //目标目录
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\xuexi\\nai1.jpg"));

        int by;
        while ((by = bis.read())!=-1){
            bos.write(by);
        }
        bos.close();
        bis.close();
    }
}
